package cn.tansanqinger.agency;

import java.lang.reflect.InvocationHandler;

interface IMessage{
    void send();
}
class MessageImpl implements IMessage{
    @Override
    public void send(){
        System.out.println("发送消息：www.tansanqinger.cn");
    }
}
class MessageImplProxy implements IMessage{
    MessageImpl message;//正常业务实现
    public MessageImplProxy(MessageImpl message) {
        this.message = message;
    }
    @Override
    public void send() {
        if(this.connect()){
            message.send();
            this.close();
        }
    }
    public boolean connect(){
        System.out.println("发送消息通道打开……");
        return true;
    }
    public void close(){
        System.out.println("关闭消息发送通道……");
    }
}
class Factory{//使用工厂设计模式
    private Factory(){}//构造方法私有化
    public static IMessage getInstance(){
        return new MessageImplProxy(new MessageImpl());
    }
}
public class StaticState {
    public static void main(String[] args) {
        IMessage iMessage = Factory.getInstance();
        iMessage.send();
    }
}
